package controllers;

import beans.Ordertable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import services.impl.OrderServicesImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private OrderServicesImpl osi;

    @RequestMapping("/order")
    public List order(){
        List<Ordertable> list = osi.selectList();
        return list;
    }

    @RequestMapping("/createorder")
    public String createOrder(@RequestBody Ordertable order){
        osi.insertSelective(order);
        return null;
    }

    @RequestMapping("/editorder")
    public String editOrder(@RequestBody Ordertable order){
        osi.updateByPrimaryKeySelective(order);
        return null;
    }

    @RequestMapping("/detailsorder")
    public Ordertable detailsOrder(HttpServletRequest request){
        int i = Integer.parseInt(request.getParameter("orderId"));
        Ordertable order= osi.selectByPrimaryKey(i);
        return order;
    }

    @RequestMapping("/searchorder")
    public List<Ordertable> searchOrder(@RequestBody Map<String,String> request){
        String select = request.get("selectText");
        String input = request.get("inputText");
        List<Ordertable> list = osi.selectSelective(select,input);
        return list;
    }

    @RequestMapping("/deleteorder")
    public String deleteOrder(HttpServletRequest request){
        int i = Integer.parseInt(request.getParameter("orderId"));
        osi.deleteByPrimaryKey(i);
        return null;
    }


}
